package com.zoe.app.runner;

import cn.hutool.core.util.ArrayUtil;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author Zoe.Zhang
 * @date 2021/10/10
 * @description
 */
@Component
public class DynamicApplicationRunner1 implements ApplicationRunner {
    /**
     * 当系统启动时,run方法会被触发
     *
     * @param args
     * @throws Exception
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 获取没有键的参数,获取到的参数和CommandRunner的参数一致
        System.out.println("DynamicApplicationRunner1" + args.getNonOptionArgs());
        // 获取所有的键和值
        for (String optionName : args.getOptionNames()) {
            System.out.println(optionName + "====" + args.getOptionValues(optionName));
        }
        // 获取所有的命令行参数
        System.out.println("DynamicApplicationRunner1" + ArrayUtil.toString(args.getSourceArgs()));
    }
}
